package com.platform.web.provider;

import com.baomidou.mybatisplus.plugins.Page;
import com.platform.web.mapper.SysUserMapper;
import com.platform.web.model.SysUser;
import com.platform.web.service.IUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author pengshuiming
 * @date 2018/6/9
 */
@Component("userService")
public class UserServiceImpl implements IUserService {
    @Resource
    SysUserMapper userMapper;
    @Override
    public int saveUser(SysUser user) {
        return userMapper.insert(user);
    }

    @Override
    public SysUser selectUserById(String id) {
        return userMapper.selectById(id);
    }

    @Override
    public Map<String, Object> selectUserListByPage(Page pageInfo) {
        Map<String,Object> map = new HashMap<>(2);
        //分页查询
        List<SysUser> sysUsers = userMapper.selectPage(
                pageInfo, null
        );
        //用PageInfo对结果进行包装
        Map<String,Object> resultMap = new HashMap<>(2);
        resultMap.put("data",sysUsers);
        resultMap.put("total",pageInfo.getTotal());
        resultMap.put("pages",pageInfo.getPages());
        return resultMap;
    }
}
